package spring.controller;

import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;

@Controller
@RequestMapping("/mdm/api/v1/devices/{deviceId}")
public class CheckInController {

    @RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    public String authority(@PathVariable String deviceId, HttpServletRequest req, HttpServletResponse res) throws IOException {
        System.out.println("deviceId = " + deviceId);
        System.out.println("CheckInController");
        InputStream inputStream = req.getInputStream();
        String str = IOUtils.stream2String(inputStream, "utf-8");
        System.out.println("str = " + str); // ok

        JSONObject json = new JSONObject(str);
        String str2 = json.toString();
        System.out.println("str2 = " + str2); // ok

        return "checkIn Succ";
    }
}
